variable declaration in javascript [migrated]
        Posted  
        
            by 
                ShaggyInjun
            
        on Programmers
        
        See other posts from Programmers
        
            or by ShaggyInjun
        
        
        
        Published on 2013-11-11T22:17:41Z
        Indexed on 
            2013/11/12
            4:15 UTC
        
        
        Read the original article
        Hit count: 244
        
JavaScript
I have been doing something like this for a while and I have never seen any errors. But, unfortunately, I have never been able to explain why this works.
The first line creates a variable which points to a function. The second line just adds func2 to func1 separated by a dot and defines a function.  
If I add a var in front of func1.func2 then I see a compilation error. 
func1.func2 = function(){};
Error
SyntaxError: missing ; before statement
var func1.func2 = function(){};
What type was func1 on first line 1 and what did it become on line 2.
var func1 = function(){};
func1.func2 = function(){};
Thanks Venkat
© Programmers or respective owner